package xyz.iguilty.workflow.model;


import lombok.Getter;
import lombok.Setter;

import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@MappedSuperclass
@Getter@Setter
public abstract class BusinessModel {
    @Transient
    public Map<String,Object> variables = new HashMap<>();
    /**
     * 主键
     */
    @Id
    public String id;

    /**
     * 流程实例id
     */
    public String processInstanceId;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 建单人
     */
    private String createBy;

    /**
     * 申请理由
     */
    private String applyReason;

    /**
     * 流程标题 如XXX的出差申请 yyyy-MM-dd
     */
    private String title;

    /**
     * 获取流程定义key
     * @return
     */
    public abstract String getProcessDefinitionKey();

    /**
     * 获取流程定义名称
     * @return
     */
    public abstract String getProcessDefinitionName();

    /**
     * 获取业务id
     * @return
     */
    public String getBusinessKey(){
        return this.getId();
    }

    public String getTitle(){
        return null;
    }


    /**
     * 生成业务id
     * @return
     */
    public String generateBusinessKey(){
        String businessKey = UUID.randomUUID().toString();
        this.setId(businessKey);
        return businessKey;
    }

    /**
     * 获取建单人
     * @return
     */
    public String getInitiator(){
        return this.getCreateBy();
    }

    /**
     * 获取申请人,默认为建单人
     * @return
     */
    public String getApplicant(){
        return this.getInitiator();
    }

    /**
     * 添加流程变量
     * @param key
     * @param value
     */
    public void addVariable(String key,Object value){
        this.variables.put(key,value);
    }

}
